#ifndef SHELL_H_
#define SHELL_H_

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <strings.h>

#include "parser.h"
#include "instance.h"
#include "./sharedMemory/sharedMemory.h"
#include "Task.h"

/**
 * Name of the named fifo
 */
#define NAMED_FIFO "fifo"

/**
 * User data entered in shell
 */
char userData[MAX_CMDLINE_LEN];

/**
 * Creates the named fifo
 */
void createMkfifo(void);

/**
 * Closes the named fifo 
 */
void closeMkfifo(void);

/**
* Terminates all the running object processes by sending them a sigkill signal
*/
void endAllObjectProcess(void);
	
/**
 * Prints the shell prompt and stores the user input into the userData buffer
 */
void shellInit(void);

/**
 * Exits the shell and clears everything needed
 */
void exitShell(void);

/**
 * Dispatches a task contained in the userData according to the keyword retrieve from stdin
 */
void dispatchTask(void);

/**
 * Delegates the creation of the object to the launch process giving it
 * the appropriate parameters on it standard input
 */
void processObjectCreation(Command command);

/**
 * Creates a new task from command. A task is created for a particular object.
 * @param command the command received from shell
 * @param t a pointer to as task structure
 */
void processWork(Command command);

/**
 * Sends a task t to pipe identified by destinationFd
 * @param t a pointer to the task to send
 * @param destinationFd the file descriptor of the pipe where to send the task
 */
void sendTask(Task* t, int destinationFd);

/**
 * Frees the memory used by object defined in varname structure field
 */
void processFree(Command command);

/**
 * Tells the process described by field objectName in structure to wait for the 
 * termination of the process described by the targetObjectName field structure
 */
void processWaitfor(Command command);

/**
 * Tells all the processes to wait
 */
void processWaitall(void);
 
 
#endif /* SHELL_H_ */
